This page has been superceded by a wiki version of this example: StringAndNumberLiteralsExample
/*
File: d069.d
Author: Justin C. Calvarese
Website: http://jcc_7.tripod.com/d/
License: Public Domain
Purpose:
Since D 0.69, integer and floating point literals
can have embedded underscores (_) for formatting purposes.
This code demonstrates those features and more...
*/
const int hundred = 100;
const int million = 1_000_000;
/*
Also added in 0.69...
x"0a AA BF" style hex strings.
*/
const char[] myName = x"4A 75 73 74 69 6E";
const char[] notRaw = "string\tstring";
/*
Raw (what-you-see-is-what-you-get) strings
implemented in D 0.69
*/
const char[] raw1 = r"string\tstring";
const char[] raw2 = `string\tstring`;
const char[] raw3 = `apostrophe: ' fancy quote: ` ~ "`";
/* See how the strings are automatically concatenated... */
const char[] oneToFive = "one" \t "two" \t "three" \t "four" \t \t "five";
/* Binary Notation: I'm saying "two" */
const int binTwo = 0b10;
const int binFancyTwo = 0b000_0010;
/* Hexadecimal Notation: I'm saying "16" */
const int hexSixteen = 0x10;
const int hexFancySixteen = 0x00_10;
/* Hexadecimal Notation: I'm saying "8" */
const int octEight = 010;
int main()
{
/* Print "1000000" */
printf("%i\n", million);
/* Print "2" */
printf("%i\n", binTwo);
/* Print "16" */
printf("%i\n", hexSixteen);
/* Print "8" */
printf("%i\n", octEight);
/* Print "Justin" */
printf("%.*s\n", myName);
/* Print a string with backslashed characters */
printf("\"Invisible\" backslashed characters: %.*s\n", notRaw);
/* Prints a what-you-see-is-what-you-get string */
printf("What-you-see-is-what-you-get [1]: %.*s\n", raw1);
/* Prints a what-you-see-is-what-you-get string */
printf("What-you-see-is-what-you-get [2]: %.*s\n", raw2);
/* Prints a what-you-see-is-what-you-get string */
printf("What-you-see-is-what-you-get [3]: %.*s\n", raw3);
/* Prints one to five */
printf("one-to-five: %.*s\n\n", oneToFive);
printf("This is the first line.
This is the second line.
I'd say that D is pretty darn cool (third line).
");
return 0;
}